home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / geomutil / ucd / stack.c < prev    next >
C/C++ Source or Header  |  1993-03-25  |  983b  |  49 lines

  1. #include "polylistP.h"
  2.     static int BlockSize, array_size;
  3.     static Poly *mystack, *stackptr;
  4.        static int count = 0, debug = 0;
  5.  
  6. int
  7. initstack()
  8. {
  9.         array_size = 1;
  10.         BlockSize = 1024;
  11.     count = 0;
  12.         if ((mystack = OOGLNewN (Poly, BlockSize )) == (Poly *) NULL) return(0);
  13.     stackptr = mystack;
  14.     return(1);
  15. }
  16.     
  17. int
  18. push(pp)
  19. Poly *pp;
  20. {
  21.     register int i;
  22.     if (stackptr >= &mystack[BlockSize*array_size])    { 
  23.     if (debug) 
  24.         fprintf(stderr,"allocating again: size is now %d\n",array_size*BlockSize);
  25.     array_size = array_size*2;
  26.         if ((mystack = OOGLRenewN(Poly,mystack, array_size*BlockSize)) == (Poly *) NULL) return (0);
  27.     stackptr = &mystack[count];
  28.     }
  29.     *stackptr = *pp;
  30.     if ((stackptr->v = OOGLNewN(Vertex *, pp->n_vertices)) == (Vertex **) NULL)
  31.     return(0);
  32.     for (i=0; i<pp->n_vertices; ++i)  stackptr->v[i] = pp->v[i];
  33.     stackptr++;
  34.     count++;
  35.     return(1);
  36. }
  37.     
  38. int
  39. getsize()
  40. {
  41.     return(count);
  42. }
  43.  
  44. Poly *
  45. getstack()
  46. {
  47.     return(mystack);
  48. }
  49.